#include <QtGui>
#include <QMessageBox>
#include <iostream>
#include "../include/gui_qt_demo/uiInclude/main_window.h"

using namespace Qt;

MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
	: QMainWindow(parent)
{
  ui.setupUi(this); //
  QObject::connect(ui.actionAbout_Qt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt())); //
  dial_needle_ = new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, true, Qt::gray, Qt::darkGray);
  ui.Dial_vel->setNeedle(dial_needle_);
  ui.Dial_yvel->setNeedle(dial_needle_);
  
  initWork(); 
}

MainWindow::~MainWindow() {

}

void MainWindow::initWork(){
  loadTab();
  builder_ = new Builder();
  loadUi();
}

void MainWindow::closeEvent(QCloseEvent *event)
{
  QMainWindow::closeEvent(event);
}

void MainWindow::loadTab(){
  Tab tab;
  tab.sort = TabSort::ROSCONN;
  tab.tab_name = "ROS连接";
  tab_name_v_.push_back(tab);
  tab.sort = TabSort::RVIZSHOW;
  tab.tab_name = "RVIZ";
  tab_name_v_.push_back(tab);
  tab.sort = TabSort::NAVPATH;
  tab.tab_name = "路径点设置";
  tab_name_v_.push_back(tab);
}

void MainWindow::loadUi(){//添加界面元素
  std::vector<Tab>::iterator tab_it_ = tab_name_v_.begin();
  for(;tab_it_ != tab_name_v_.end();tab_it_++){
    TabBase* newTab = builder_->buildTab(tab_it_->sort);
    tab_ptr_v_.push_back(newTab);
    ui.tab_manager->addTab(newTab->getTab(),tab_it_->tab_name.c_str());
  }
}


